package org.shopen.puremvc
{
	import org.puremvc.as3.patterns.facade.Facade;
	import org.puremvc.as3.patterns.observer.Notification;
	import org.shopen.puremvc.controller.ConfigureContentCommand;
	import org.shopen.puremvc.controller.popupHandlers.HandleAboutRequestCommand;
	import org.shopen.puremvc.controller.popupHandlers.HandleGeneralErrorCommand;
	import org.shopen.puremvc.controller.popupHandlers.HandleHelpRequestCommand;
	import org.shopen.puremvc.controller.startup.StartupCommand;
	import org.shopen.puremvc.controller.testing.SelectTestingCommand;
	import org.shopen.puremvc.controller.testing.TestOutCommand;
	import org.shopen.puremvc.controller.theory.InitTheoriesCommand;
	import org.shopen.puremvc.controller.theory.LoadTheoryCommand;
	import org.shopen.puremvc.controller.theory.SelectStageCommand;

	public class ApplicationFacade extends Facade
	{
		public static const NAME : String = "ApplicationFacade";
		private static const delim : String = ".";
		
		public static const STARTUP : String = NAME + delim + "STARTUP";
		
		public static function getInstance() : ApplicationFacade
		{
			if (instance == null)
			{
				instance = new ApplicationFacade();
			}
			return instance as ApplicationFacade;
		}
		
		public function startup(application : StudyAir) : void
		{
			sendNotification(STARTUP, application);
		}
		
		override public function sendNotification(notificationName:String, body:Object=null, type:String=null):void
		{
			trace(notificationName + " : " + type);
			notifyObservers(new Notification(notificationName, body, type));
		}
		
		override protected function initializeController():void
		{
			super.initializeController();
			registerCommand(ApplicationFacade.STARTUP, StartupCommand);
			registerCommand(ApplicationConstants.CONFIGURE_CONTENT, ConfigureContentCommand);
			registerCommand(ApplicationConstants.LOAD_THEORY_META, InitTheoriesCommand);
			registerCommand(ApplicationConstants.LOAD_THEORY, LoadTheoryCommand);
			registerCommand(ApplicationConstants.SELECT_STAGE, SelectStageCommand);
			registerCommand(ApplicationConstants.SELECT_TESTING, SelectTestingCommand);
			registerCommand(ApplicationConstants.TESTOUT, TestOutCommand);
			
			// popups related commands
			registerCommand(ApplicationConstants.GENERAL_ERROR, HandleGeneralErrorCommand);
			registerCommand(ApplicationConstants.HELP_REQUEST, HandleHelpRequestCommand);
			registerCommand(ApplicationConstants.ABOUT_REQUEST, HandleAboutRequestCommand);
		}
	}
}